package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/login")
public class LoginServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			resp.setContentType("text/html;charset=utf-8");
			PrintWriter pw = resp.getWriter();
			req.setCharacterEncoding("utf-8");
			String user = req.getParameter("username");
			String psw = req.getParameter("psw");
			if(user.equals("张三")&&psw.equals("123")) {
				pw.write("<html><head><title>登录成功的界面</title></head>");
				pw.write("<body bgcolor='pink'>");
				pw.write("用户"+user+"你好,欢迎登录管理系统!<hr>");
				pw.write("<table><tr><td>学生姓名</td><td>学生学号</td><td>学生宿舍号</td><td>学生手机号</td></tr>");
				pw.write("<tr><td>小明</td><td>001</td><td>3-423</td><td>158898989</td></tr>");
				pw.write("<tr><td>小强</td><td>002</td><td>3-424</td><td>158898444</td></tr>");
				pw.write("<tr><td>小红</td><td>002</td><td>3-425</td><td>158898555</td></tr>");
				pw.write("</table></body></html>");
			}else {
				pw.write("<html><head><title>登录失败的界面</title></head>");
				pw.write("<body bgcolor='orange'>");
				pw.write("对不起用户名或密码错误,请重新登录!<a href='login.html'>重新登录</a><hr>");
				pw.write("</body></html>");
		}
			pw.close();
	}
	
}
